package com.liwenfeng.file;

/*
 * 递归调用练习题
 * 啤酒2元一瓶，4个盖子可以换一瓶，2个空瓶可以换一瓶，10元可以喝多少瓶
 * */
public class DrinkBeer {
    public int totalNumber = 0;
    // 记录剩余空瓶
    public int lastBottleNumber = 0;
     // 剩余瓶盖
    public int lastCoverNumber = 0;

    public void buy(int money) {
        int buyNumber = money / 2;
        totalNumber += buyNumber;
        int balance = money - buyNumber * 2 + ((buyNumber + lastBottleNumber) / 2) * 2 + ((buyNumber + lastCoverNumber) / 4) * 2;
        lastBottleNumber = (buyNumber + lastBottleNumber) % 2;
        lastCoverNumber = (buyNumber + lastCoverNumber) % 4;
        if (balance >= 2) buy(balance);
    }

    public static void main(String[] args) {
        DrinkBeer drinkBeer = new DrinkBeer();
        drinkBeer.buy(10);
        System.out.println("喝啤酒："+drinkBeer.totalNumber+"，剩余空瓶："+drinkBeer.lastBottleNumber+"，剩余瓶盖："+drinkBeer.lastCoverNumber);
    }
}
